package Leo.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.SourceLocation;
import org.springframework.stereotype.Component;

/**
 * aop 切面类
 */
@Aspect
@Component
public class ControllerAspect {

    /**
     * 解释为什么用两个.*
     * controller是一个package，第一个.*表示package下所有的class
     * 第二个.*表示该class下所有的method
     */
    @Pointcut("execution(public * Leo.controller.*.*(..))")
    public void webLog(){}

    @Before("webLog()")
    public void paramLog(JoinPoint joinPoint){
        SourceLocation sourceLocation = joinPoint.getSourceLocation();
        Object target = joinPoint.getTarget();
        joinPoint.getThis();
        Object[] args = joinPoint.getArgs();
        for (Object arg : args) {
            System.out.println(arg);
        }
    }
}
